package com.zhangyongyi.carhome.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TabHost;

import com.zhangyongyi.carhome.R;
import com.zhangyongyi.carhome.fragment.findcar.FindCarFragment;
import com.zhangyongyi.carhome.fragment.forum.ForumFragment;
import com.zhangyongyi.carhome.fragment.person.PersonFragment;
import com.zhangyongyi.carhome.fragment.recommend.RecommendFragment;
import com.zhangyongyi.carhome.tools.DayNightMode;

import cn.sharesdk.framework.ShareSDK;

/**
 * 个人项目
 */

public class MainActivity extends AppCompatActivity {
    private TabHost tabHost;
    private FragmentManager fm;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //在Activity开始初始化视图前去应用才能生效
        DayNightMode.onActivityCreateSetTheme(this);

        setContentView(R.layout.activity_main);

        //*
        ShareSDK.initSDK(this);


        fm = getSupportFragmentManager();
        initTabHost();
        init();
        //*
//        showShare();
    }

    private void initTabHost() {
        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();

        TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1");
        View view1 = getLayoutInflater().inflate(R.layout.tab_recommend, null);
        tab1.setIndicator(view1);
        tab1.setContent(R.id.tab_recommend);
        tabHost.addTab(tab1);

        TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2");
        View view2 = getLayoutInflater().inflate(R.layout.tab_forum, null);
        tab2.setIndicator(view2);
        tab2.setContent(R.id.tab_forum);
        tabHost.addTab(tab2);

        TabHost.TabSpec tab3 = tabHost.newTabSpec("tab3");
        View view3 = getLayoutInflater().inflate(R.layout.tab_car, null);
        tab3.setIndicator(view3);
        tab3.setContent(R.id.tab_car);
        tabHost.addTab(tab3);


        TabHost.TabSpec tab4 = tabHost.newTabSpec("tab4");
        View view4 = getLayoutInflater().inflate(R.layout.tab_user, null);
        tab4.setIndicator(view4);
        tab4.setContent(R.id.tab_user);
        tabHost.addTab(tab4);

    }

    private void init() {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.tab_recommend, new RecommendFragment());
        ft.replace(R.id.tab_forum, new ForumFragment());
        ft.replace(R.id.tab_car, new FindCarFragment());

        ft.replace(R.id.tab_user, new PersonFragment());

        ft.commit();


    }




    @Override
    protected void onDestroy() {
        //*
        ShareSDK.stopSDK(this);
        super.onDestroy();
    }
}
